<template>
  <div id="app">
    <div class="container">
      <!-- 注册表单 -->
      <div v-if="isSignUp" class="form-container">
        <h1>注册</h1>
        <input v-model="username" type="text" placeholder="用户名" />
        <input v-model="email" type="email" placeholder="邮箱" />
        <input v-model="password" type="password" placeholder="密码" />
        <button @click="handleSignUp">注册</button>
        <p @click="toggleForm">已有账号？登录</p>
      </div>
      <!-- 登录表单 -->
      <div v-else class="form-container">
        <h1>登录</h1>
        <input v-model="email" type="email" placeholder="邮箱" />
        <input v-model="password" type="password" placeholder="密码" />
        <button @click="handleSignIn">登录</button>
        <p @click="toggleForm">没有账号？注册</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 表单数据
const isSignUp = ref(true);
const username = ref('');
const email = ref('');
const password = ref('');

// 切换表单
const toggleForm = () => {
  isSignUp.value =!isSignUp.value;
};

// 注册处理函数
const handleSignUp = () => {
  console.log('注册信息：', {
    username: username.value,
    email: email.value,
    password: password.value
  });
  // 这里可以添加实际的注册逻辑，如发送请求到后端
};

// 登录处理函数
const handleSignIn = () => {
  console.log('登录信息：', {
    email: email.value,
    password: password.value
  });
  // 这里可以添加实际的登录逻辑，如发送请求到后端
};
</script>

<style scoped>
#app {
  font-family: Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f4f4f9;
}

.container {
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.form-container {
  text-align: center;
}

input {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  border: 1px solid #ccc;
  border-radius: 5px;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

p {
  margin-top: 10px;
  cursor: pointer;
  color: #007bff;
}
</style>